Repository navigation
Minify and compress schemas in binaries - #6722
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
🟡 Changes recommended
The PowerShell -match operation overwrites the resource match collection in $Matches, causing resource generation to fail and blocking the AppInstallerCLITests build.
1 open issue
What changed in this PR
This PR reduces WinGet’s native binary size by minifying and compressing embedded JSON schemas at build time, then decompressing them when loading schemas for validation.
Changes:
- Adds a shared build pipeline for JSON minification and MSZIP resource compression.
- Updates resource and schema loaders to decompress embedded data before parsing.
- Adds generator tests, native resource tests, documentation, and a release note.
| File | Description |
|---|---|
| src/WinGetSchemas/WinGetSchemas.vcxitems.filters | Classifies package-schema resources as custom-build inputs. |
| src/WinGetSchemas/WinGetSchemas.vcxitems | Enables package-schema compression and dependency tracking. |
| src/targets/Test-CompressedResources.ps1 | Tests generation, round trips, cleanup, and resource identifiers. |
| src/targets/Generate-CompressedResources.ps1 | Generates compressed payloads and rewritten resource scripts. |
| src/targets/CompressedResources.targets | Integrates compression, output checks, and cleanup into native builds. |
| src/targets/CompressedResources.md | Documents resource compression, usage, and validation. |
| src/targets/CompressedResources.cs | Implements compression, decompression, and JSON minification helpers. |
| src/ManifestSchema/ManifestSchema.vcxitems.filters | Classifies manifest-schema resources as custom-build inputs. |
| src/ManifestSchema/ManifestSchema.vcxitems | Enables manifest-schema compression and dependency tracking. |
| src/Directory.Build.targets | Imports compression targets for native projects. |
| src/AppInstallerSharedLib/Resources.cpp | Implements decompressed resource loading. |
| src/AppInstallerSharedLib/Public/winget/Resources.h | Declares decompressed resource APIs. |
| src/AppInstallerSharedLib/Public/winget/JsonSchemaValidation.h | Documents compressed schema loading and adds forward declarations. |
| src/AppInstallerSharedLib/Public/winget/Compression.h | Declares a pointer-and-size decompression overload. |
| src/AppInstallerSharedLib/JsonSchemaValidation.cpp | Decompresses schema resources before parsing. |
| src/AppInstallerSharedLib/Compression.cpp | Implements pointer-and-size decompression. |
| src/AppInstallerCommonCore/Manifest/ManifestSchemaValidation.cpp | Routes manifest schemas through the compressed resource loader. |
| src/AppInstallerCLITests/TestData/CompressedResourceInvalidJson.txt | Adds an invalid-JSON fixture. |
| src/AppInstallerCLITests/Resources.cpp | Tests binary round trips, schema parity, and loading failures. |
| src/AppInstallerCLITests/CompressedResources.rc | Defines compressed-resource test fixtures. |
| src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters | Registers new test resources in project filters. |
| src/AppInstallerCLITests/AppInstallerCLITests.vcxproj | Enables compressed fixtures and original-resource comparisons. |
| doc/release-notes/1.31/compress-embedded-json-schemas.md | Announces smaller native binaries. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The pipeline spans MSBuild tracking, RC compilation, and Windows compression APIs, but this review environment could not validate its build lifecycle or native-resource interoperability.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
| } | ||
| $before = ($records | Measure-Object OriginalBytes -Sum).Sum | ||
| $after = ($records | Measure-Object CompressedBytes -Sum).Sum | ||
| Write-Host "Packed $($records.Count) resources from '$ResourceScript': $before -> $after bytes." |
There was a problem hiding this comment.
nit: Write-Host doesn't work when there is no host and is not able to be suppressed, captured, or redirected reliably in all environments. Write-Information or Write-Output are PowerShell's preferred cmdlets
Also applies to the the Test script
There was a problem hiding this comment.
I read the docs as: Host is for the human, Output is for the pipeline. These are descriptive logging messages, not data for the pipeline to consume later.
Also:
Starting in Windows PowerShell 5.0, Write-Host is a wrapper for Write-Information.
ranm-msft
left a comment
There was a problem hiding this comment.
One blocking build issue below.
There was a problem hiding this comment.
🔵 Needs a closer look
Generator tests do not cover the Windows-only MSBuild/RC integration, and clean/incremental builds, deleted-payload recovery, and generator/runtime interoperability could not be validated here.
No open issues 🎉
Review effort: Balanced
| } | ||
| } | ||
|
|
||
| public static string MinifyJson(string input) |
There was a problem hiding this comment.
I would prefer if we did ConvertTo-Json -Compress or used System.Text.Json.JsonSerializer with WriteIndented=false. That may require the script to be PowerShell only and not support Windows PowerShell, but I don't see a reason not to do that.
There was a problem hiding this comment.
The custom minifier allows for syntax level validation that the result matches the original. Those other paths require semantic validation, which rely on us having complete coverage over the schema space. While that is something we should strive for, I can't guarantee it. But if we do have it, we can also feel confident in the custom code.

📖 Description
Minifies and compresses JSON schemas before including them as resources in our binaries. This saved ~750KiB in local builds.
The compressed resource streams are all created at build time. No additional overhead should be incurred for updating or adding new schemas.
Decompressing the resource streams every time does incur a minor performance penalty. Minification provides an even smaller gain. Together this increases validation times very slightly, depending on the schema being used (at most 10%).
If this becomes an issue (and the winget-pkgs service is the only place I can imagine it would), we should move to caching the parsed schemas at runtime. My investigation into that showed that parsing the schema resources takes 15-20% of the overall validation time. Caching the parsed JSON would then cover both the decompression and parsing. But I suspect even in validation heavy operations the validation itself accounts for a tiny amount of the overall time.
🔍 Validation
New tests are added specifically for compressed resources and the build target.
Microsoft Reviewers: Open in CodeFlow